package com.yiqi.zhiyuan.common.widget.citypicker.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiqi.zhiyuan.R;
import com.yiqi.zhiyuan.entity.vo.CarBrandVO;

import java.util.ArrayList;
import java.util.List;

/**
 * author zaaach on 2016/1/26.
 */
public class HotCityGridAdapter extends BaseAdapter {
    private Context mContext;
    private List<CarBrandVO> mCities;

    public HotCityGridAdapter(Context context) {
        this.mContext = context;
        mCities = new ArrayList<>();
        mCities.add(new CarBrandVO("1","大众",R.mipmap.ic_car_brand_dz));
        mCities.add(new CarBrandVO("8","福特",R.mipmap.ic_car_brand_ford));
        mCities.add(new CarBrandVO("14","本田",R.mipmap.ic_car_brand_bt));
        mCities.add(new CarBrandVO("3","丰田",R.mipmap.ic_car_brand_ft));
        mCities.add(new CarBrandVO("38","别克",R.mipmap.ic_car_brand_bk));
        mCities.add(new CarBrandVO("33","奥迪",R.mipmap.ic_car_brand_aodi));
        mCities.add(new CarBrandVO("12","现代",R.mipmap.ic_car_brand_xd));
        mCities.add(new CarBrandVO("71","雪佛兰",R.mipmap.ic_car_brand_xfl));
        mCities.add(new CarBrandVO("36","奔驰",R.mipmap.ic_car_brand_bc));
        mCities.add(new CarBrandVO("15","宝马",R.mipmap.ic_car_brand_bmw));
    }

    @Override
    public int getCount() {
        return mCities == null ? 0 : mCities.size();
    }

    @Override
    public CarBrandVO getItem(int position) {
        return mCities == null ? null : mCities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        HotCityViewHolder holder;
        if (view == null){
            view = LayoutInflater.from(mContext).inflate(R.layout.item_hot_city, parent, false);
            holder = new HotCityViewHolder();
            holder.name = (TextView) view.findViewById(R.id.tv_hot_city_name);
            holder.image =  view.findViewById(R.id.tv_hot_city_image);
            view.setTag(holder);
        }else{
            holder = (HotCityViewHolder) view.getTag();

        }
        holder.name.setText(mCities.get(position).getBname());
        holder.image.setImageResource(mCities.get(position).getImageRes());
        return view;
    }

    public static class HotCityViewHolder{
        TextView name;
        ImageView image;
    }
}
